package cn.itcast.heima2;

import com.wushijia.model.User;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.concurrent.CopyOnWriteArrayList;

public class CollectionModifyExceptionTest {

  public static void main(String[] args) {
    Collection users = new CopyOnWriteArrayList();

    //new ArrayList();
    users.add(new User("zhangsan", 28));
    users.add(new User("lisi", 25));
    users.add(new User("wangwu", 31));
    Iterator itrUsers = users.iterator();
    while (itrUsers.hasNext()) {
      System.out.println("aaaa");
      User user = (User) itrUsers.next();
      if ("zhangsan".equals(user.getName())) {
        users.remove(user);
        //itrUsers.remove();
      } else {
        System.out.println(user);
      }
    }
  }
}
